package tliasmanagement.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import tliasmanagement.anno.Log;
import tliasmanagement.pojo.Result;
import tliasmanagement.pojo.Student;
import tliasmanagement.pojo.StudentQueryParam;
import tliasmanagement.service.StudentService;

import java.util.List;

@RequestMapping("/students")
@RestController
public class StudentController {
    @Autowired
    private StudentService studentService;

    /**
     * 分页查询
     * @param studentQueryParam 页码
     * */
    @GetMapping
    public Result page(StudentQueryParam studentQueryParam) {
        return Result.success(studentService.page(studentQueryParam));
    }

    /**
     * 新增学生
     * @param student 新增的学生
     * */
    @Log
    @PostMapping
    public Result add(@RequestBody Student student) {
        studentService.add(student);
        return Result.success();
    }

    /**
     * 获取学生详情
     * @param id 学生id
     * */
    @GetMapping("/{id}")
    public Result get(@PathVariable Integer id) {
        return Result.success(studentService.getDetailInfo(id));
    }

    /**
     * 修改学生信息
     * @param student 修改的学生信息
     * */
    @Log
    @PutMapping
    public Result update(@RequestBody Student student) {
        studentService.update(student);
        return Result.success();
    }

    /**
     * 删除学生
     * @param ids 学生id列表
     * */
    @Log
    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable List<Integer> ids) {
        studentService.delete(ids);
        return Result.success();
    }
}
